
using System.Collections.Generic;
using com.tc.zigbee.entity.device.config;
using com.tc.zigbee.entity;
using com.tc.zigbee.zcl;
using com.tc.zigbee.mt.request;
using com.tc.gateway.device;
using com.tc.zigbee.mt;
using com.tc.util;
namespace com.tc.zigbee.entity.device
{
    abstract public class ZigbeeDevice : AbstractDevice
    {

        protected Endpoint endpoint;
	    protected ZigbeeManager manager;

        override public string description()
        {
            return this.endpoint.description();
        }
	public ZigbeeDevice(Endpoint endpoint, ZigbeeManager m) {

		this.manager = m;
		this.endpoint = endpoint;
	}
	
	public Endpoint getEndpoint() {
		return endpoint;
	}

	override public string getId() {
		return DataUtil.hex(this.endpoint.getParent().getIeeeAddress()) + DataUtil.hex(endpoint.getEndpointId());

	}

    override public string getType()
    {
		return DataUtil.hex(this.endpoint.getProfileId()) + DataUtil.hex(endpoint.getDeviceId());

	}

    override public void read(List<short> attribs)
    {
		byte[] zclcommand = ZclCommandCreator.read((byte)0, attribs);
		MtCommand mc = RequestFactory.MtAfDataRequest((byte)2,
				this.endpoint.getParent().getNwkAddress(), 
				//(short)1,
				endpoint.getEndpointId(), 
				(byte)manager.getRemoteControl().getEndpointId(), 
				ZclConstants.ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL, 
				(byte)0, 
				(byte)0, 
				(byte)2, 
				(byte)zclcommand.Length, 
				zclcommand
				);
	}

    override public object getAttribute(short cluster, short attr)
    {
		// TODO Auto-generated method stub
		return endpoint.getAttribute(cluster, attr);
	}

	override 	public string ToString() {
		if(this.getName() != null)
			return this.getName();

		return endpoint.ToString();
	}

        public ZigbeeDevice(Endpoint endpoint)
        {

            this.endpoint = endpoint;
        }
        override abstract public void action();
        

    }
}
